
package com.wyzz.hr.bo.impl;

import java.util.List;
import org.hibernate.criterion.*;

import com.wyzz.hr.bo.IContractTypeBo;
import com.wyzz.hr.dao.IContractTypeDao;
import com.wyzz.hr.pojo.ContractType;


public class ContractTypeBoImpl implements IContractTypeBo {

	public ContractTypeBoImpl() {
	}

	public List FindAllEcptype() {
		DetachedCriteria dc = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.ContractType.class);
		dc.addOrder(Order.asc("ectSortId"));
		return contractDao.findByCriteria(dc);
	}

	public void addContractType(ContractType contractType) {
		contractDao.saveObject(contractType);
	}

	public String delContractType(String id) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Empcontract.class);
		detachedCriteria.add(Restrictions.eq("contractType.id", id));
		List list = contractDao.findByCriteria(detachedCriteria);
		if (list.size() == 0) {
			contractDao.deleteObject(com.wyzz.hr.pojo.ContractType.class, id);
			return "";
		} else {
			return "\u8BE5\u5408\u540C\u7C7B\u578B\u6B63\u5728\u88AB\u4F7F\u7528\uFF0C\u4E0D\u80FD\u5220\u9664\uFF01";
		}
	}

	public void updateContractType(ContractType contractType) {
		contractDao.updateObject(contractType);
	}

	public IContractTypeDao getContractDao() {
		return contractDao;
	}

	public void setContractDao(IContractTypeDao contractDao) {
		this.contractDao = contractDao;
	}

	public List findByName(String name) {
		DetachedCriteria dc = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.ContractType.class);
		dc.add(Restrictions.eq("ectName", name));
		return contractDao.findByCriteria(dc);
	}

	public void saveContractTypeIdByBatch(String ids[]) {
		if (ids == null)
			return;
		int length = ids.length;
		int sortId = 1;
		for (int i = 0; i < length; i++) {
			contractDao.exeHql((new StringBuilder()).append(
					"update ContractType set ectSortId=").append(sortId)
					.append(" where id ='").append(ids[i]).append("'")
					.toString());
			sortId++;
		}

	}

	private IContractTypeDao contractDao;
}
